package ycl.security.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import ycl.common.result.REnum;
import ycl.common.result.Result;
import ycl.common.utils.ServletUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未有登录实例
 *
 * @author ycl
 * @date 2022-03-10 13:11:50
 */
@Component
@Slf4j
public class AuthEntryPointHandler implements AuthenticationEntryPoint {
	@Override
	public void commence(
			HttpServletRequest request,
			HttpServletResponse response,
			AuthenticationException e) throws IOException {
		log.info("NoLoginProviderHandler . commence . 未登录处理");
		Result<Object> result = Result.fail(REnum.USED_UNAUTHORIZED);
		ServletUtil.writeResponse(response, result);
	}
}
